<#assign StringUtils = beansWrapperFn.getStaticModels()["org.apache.commons.lang3.StringUtils"]>
WITH w_ROLE AS
  (SELECT T.*,
    row_number() over(order by T.ORDER_NUM , t.CODE) rn
  FROM C1_ROLE T
  WHERE (NOW() BETWEEN IFNULL(T.BEGIN_DATE, NOW()) AND IFNULL(T.END_DATE, NOW()) )
<#if StringUtils.isNotBlank(orgId)>
  AND T.ORG_ID = :orgId
</#if>
<#if StringUtils.isNotBlank(code)>
  AND (instr(T.code, :code) > 0
  OR instr(T.name, :code)   > 0)
</#if>
  )
SELECT T.*
FROM w_ROLE T
WHERE t.rn BETWEEN <#if (begin_row_num??)>:begin_row_num<#else>1</#if> AND <#if (end_row_num??)>:end_row_num<#else>20</#if>
